<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="" id="form">
    <input type="text" name="username" id="">
    <input type="text" name="password" id="">
    <input type="button" value="提交" id="btn">
    <input type="file" id="file">
</form>
<script>
    var btn = document.querySelector('#btn');
    var form = document.querySelector('#form')
    btn.onclick = function () {
        var formData = new FormData(form);
        const xhr = new XMLHttpRequest();
        xhr.open('post','http://localhost:3000/formdata');
        xhr.send(formData);
        xhr.onload = function () {
            if(xhr.status == 200){
                console.log(xhr.responseText)
            }
        }
    }
</script>
</body>
</html>